<template>
  <div class="treePage">
    <div class="tree">
      <p>基础自定义树形</p>
      <treeBasic :eventCategoryTree="treeData1"></treeBasic>
    </div>
    <div class="tree">
      <p>可选择自定义树形</p>
      <!-- <treeComponent :tree-data="treeData" :show-checkbox="showCheckbox"></treeComponent> -->
      <treeBasic :eventCategoryTree="treeData2" :show-checkbox="showCheckbox"></treeBasic>
    </div>
    <div class="tree">
      <p>基础树形</p>
      <el-tree :data="treeData3" default-expand-all highlight-current></el-tree>
    </div>
    <div class="tree">
      <p>可选择树形</p>
      <el-tree :data="treeData4" default-expand-all show-checkbox :default-expanded-keys="[2, 3]" :default-checked-keys="[3]" node-key="id" highlight-current></el-tree>
    </div>
    <div class="tree">
      <p>节点过滤</p>
      <el-input placeholder="输入关键字进行过滤" v-model="filterText">
      </el-input>
      <el-tree class="filter-tree" :data="treeData5" default-expand-all :filter-node-method="filterNode" ref="tree2" highlight-current>
      </el-tree>
    </div>
    <div class="tree">
      <p>柯林斯拖拽节点</p>
      <el-tree :data="treeData6" node-key="id" default-expand-all @node-drag-start="handleDragStart" @node-drag-enter="handleDragEnter" @node-drag-leave="handleDragLeave" @node-drag-over="handleDragOver" @node-drag-end="handleDragEnd" @node-drop="handleDrop" draggable :allow-drop="allowDrop" :allow-drag="allowDrag" highlight-current>
      </el-tree>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
import treeComponent from './treeComponent.vue'
import treeBasic from './treeBasic'
export default {
  name: 'treePage',
  components: {
    treeComponent,
    treeBasic
  },
  data () {
    return {
      showCheckbox: true,
      filterText: '',
      treeData1: [{
        id: 1,
        label: '一级 1',
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 4,
          label: '二级 1-1',
          addAble: true,
          delAble: true,
          WatchInfo: true,
          children: [{
            id: 9,
            label: '三级 1-1-1',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }, {
            id: 10,
            label: '三级 1-1-2',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 5,
          label: '二级 2-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 6,
          label: '二级 2-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }, {
        id: 3,
        label: '一级 3',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 7,
          label: '二级 3-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 8,
          label: '二级 3-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }],
      treeData2: [{
        id: 1,
        label: '一级 1',
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 4,
          label: '二级 1-1',
          addAble: true,
          delAble: true,
          WatchInfo: true,
          children: [{
            id: 9,
            label: '三级 1-1-1',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }, {
            id: 10,
            label: '三级 1-1-2',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 5,
          label: '二级 2-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 6,
          label: '二级 2-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }, {
        id: 3,
        label: '一级 3',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 7,
          label: '二级 3-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 8,
          label: '二级 3-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }],
      treeData3: [{
        id: 1,
        label: '一级 1',
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 4,
          label: '二级 1-1',
          addAble: true,
          delAble: true,
          WatchInfo: true,
          children: [{
            id: 9,
            label: '三级 1-1-1',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }, {
            id: 10,
            label: '三级 1-1-2',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 5,
          label: '二级 2-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 6,
          label: '二级 2-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }, {
        id: 3,
        label: '一级 3',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 7,
          label: '二级 3-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 8,
          label: '二级 3-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }],
      treeData4: [{
        id: 1,
        label: '一级 1',
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 4,
          label: '二级 1-1',
          addAble: true,
          delAble: true,
          WatchInfo: true,
          children: [{
            id: 9,
            label: '三级 1-1-1',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }, {
            id: 10,
            label: '三级 1-1-2',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 5,
          label: '二级 2-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 6,
          label: '二级 2-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }, {
        id: 3,
        label: '一级 3',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 7,
          label: '二级 3-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 8,
          label: '二级 3-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }],
      treeData5: [{
        id: 1,
        label: '一级 1',
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 4,
          label: '二级 1-1',
          addAble: true,
          delAble: true,
          WatchInfo: true,
          children: [{
            id: 9,
            label: '三级 1-1-1',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }, {
            id: 10,
            label: '三级 1-1-2',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 5,
          label: '二级 2-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 6,
          label: '二级 2-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }, {
        id: 3,
        label: '一级 3',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 7,
          label: '二级 3-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 8,
          label: '二级 3-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }],
      treeData6: [{
        id: 1,
        label: '一级 1',
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 4,
          label: '二级 1-1',
          addAble: true,
          delAble: true,
          WatchInfo: true,
          children: [{
            id: 9,
            label: '三级 1-1-1',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }, {
            id: 10,
            label: '三级 1-1-2',
            addAble: true,
            delAble: true,
            WatchInfo: true
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 5,
          label: '二级 2-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 6,
          label: '二级 2-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }, {
        id: 3,
        label: '一级 3',
        disabled: true,
        addAble: true,
        delAble: true,
        WatchInfo: true,
        children: [{
          id: 7,
          label: '二级 3-1',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }, {
          id: 8,
          label: '二级 3-2',
          addAble: true,
          delAble: true,
          WatchInfo: true
        }]
      }]
    }
  },
  watch: {
    filterText (val) {
      this.$refs.tree2.filter(val)
    }
  },
  methods: {
    // 过滤的方法
    filterNode (value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 拖拽节点的方法
    handleDragStart (node, ev) {
      console.log('drag start', node)
    },
    handleDragEnter (draggingNode, dropNode, ev) {
      console.log('tree drag enter: ', dropNode.label)
    },
    handleDragLeave (draggingNode, dropNode, ev) {
      console.log('tree drag leave: ', dropNode.label)
    },
    handleDragOver (draggingNode, dropNode, ev) {
      console.log('tree drag over: ', dropNode.label)
    },
    handleDragEnd (draggingNode, dropNode, dropType, ev) {
      console.log('tree drag end: ', dropNode && dropNode.label, dropType)
    },
    handleDrop (draggingNode, dropNode, dropType, ev) {
      console.log('tree drop: ', dropNode.label, dropType)
    },
    allowDrop (draggingNode, dropNode, type) {
      if (dropNode.data.label === '二级 3-1') {
        return type !== 'inner'
      } else {
        return true
      }
    },
    allowDrag (draggingNode) {
      return draggingNode.data.label.indexOf('三级 3-2-2') === -1
    }
  }
}
</script>
<style lang="scss" scoped>
.treePage {
  display: flex;
  width: 100%;
  height: 1400px;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: start;
  .tree {
    width: 49%;
    height: 450px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
  }
}
</style>
